package com.mybatis.boost.mapper.util;

import com.mybatis.boost.mapper.util.sql.SqlUtil;
import com.mybatis.boost.tool.StringUtil;

/**
 * @author jearton
 * @since 2016/12/16
 */
@SuppressWarnings("unused")
public abstract class OGNL {

    private final static String CLASS_NAME = "@com.mybatis.extend.mapper.util.OGNL";

    public final static String TRIM_AND_TO_LOWERCASE = CLASS_NAME + "@trimAndToLowerCase(%s)";

    public final static String REMOVE_DELIMITER = CLASS_NAME + "@removeDelimiter(%s)";

    public final static String ADD_DELIMITER = CLASS_NAME + "@addDelimiter(%s)";

    public final static String CHECK_FOR_NULL = CLASS_NAME + "@checkForNull(%s,%s)";

    public final static String CHECK_FOR_BLANK = CLASS_NAME + "@checkForBlank(%s,%s)";

    public static String trimAndToLowerCase(String s) {
        return StringUtil.trimAndToLowerCase(s);
    }

    public static String removeDelimiter(String column) {
        return SqlUtil.removeDelimiter(column);
    }

    public static String addDelimiter(String column) {
        return SqlUtil.addDelimiter(column);
    }

    public static boolean checkForNull(Object parameter, String messageIfNull) {
        if (parameter == null) {
            throw new IllegalArgumentException(messageIfNull);
        }
        return true;
    }

    public static boolean checkForBlank(String parameter, String messageIfBlank) {
        if (jodd.util.StringUtil.isBlank(parameter)) {
            throw new IllegalArgumentException(messageIfBlank);
        }
        return true;
    }
}
